#include<iostream>
#include<vector>
using namespace std;

vector<vector<int>> reshapeMatrix(vector<vector<int>>& matrix, int r, int c) {
    int m = matrix.size();
    int n = matrix[0].size();

    if (m * n != r * c) {
        return matrix;
    }

    vector<vector<int>> reshapedMatrix(r, vector<int>(c));

    for (int i = 0; i < r * c; i++) {
        reshapedMatrix[i / c][i % c] = matrix[i / n][i % n];
    }

    return reshapedMatrix;
}

int main() {
    vector<vector<int>> matrix = {{1, 2},
                                  {3, 4}};
    int r = 1;
    int c = 4;

    vector<vector<int>> reshapedMatrix = reshapeMatrix(matrix, r, c);

    cout << "重塑后的矩阵：" << endl;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cout << reshapedMatrix[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}